package cn.jiyun.user.service.impl;

import cn.jiyun.user.entity.User;
import cn.jiyun.user.mapper.UserMapper;
import cn.jiyun.user.service.IUserService;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author usian
 * @since 2022-10-25
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;


    @Override
    public String login(User user) {
        if (user==null){
            log.info("用户名为空");
            return "用户名为空";
        }
        String name = user.getName();
        String password = user.getPassword();
        QueryWrapper<User>queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(User::getName,name);
        User user1 = this.getOne(queryWrapper);
        if (user1==null){
            log.info("参数错误");
            return "参数错误";
        }
        if (user1.getName().equals(name)){
            boolean b = passwordEncoder.matches(user1.getPassword(), password);
            if (b){
                log.info("密码错误");
                return "登录失败";
            }else {
                return "登录成功";
            }
        }
        return "zhang";
    }

    @Override
    public String send(String mobile) {

        return null;
    }
}
